package com.lihuacats.bilibili.task.bilibili_task.controller;

import com.lihuacats.bilibili.task.bilibili_task.config.ConfigProperties;
import com.lihuacats.bilibili.task.bilibili_task.domain.MessageVO;
import com.lihuacats.bilibili.task.bilibili_task.task.BiliStart;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author Kurisu
 * 2019-01-31 17:51
 */
@Slf4j
@RestController
@RequestMapping("/bilibili")
public class BiliBliController {
    private final BiliStart biliStart;
    private final ConfigProperties configProperties;

    @Autowired
    public BiliBliController(final BiliStart biliStart, final ConfigProperties configProperties) {
        this.biliStart = biliStart;
        this.configProperties = configProperties;
    }

    @PutMapping("/sign")
    public MessageVO<Void> sign() {
        try {
            biliStart.start();
            return MessageVO.success();
        } catch (Exception ex) {
            log.error("系统异常", ex);
            return MessageVO.failure(ex.getMessage());
        }
    }

    @GetMapping("/check")
    public MessageVO<Void> checkConfig() {
        try {
            log.info("{}", configProperties);
            return MessageVO.success();
        } catch (Exception ex) {
            log.error("系统异常", ex);
            return MessageVO.failure(ex.getMessage());
        }
    }
}
